﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Web;
using IronOne.SalesOne.DataObjects.QuotationReportDSTableAdapters;

namespace IronOne.SalesOne.SalesOneWeb.Collection
{
    public partial class ViewReportUploadedCollection : System.Web.UI.Page
    {
        int branchCode;
        DateTime DateFrom;
        DateTime DateTo;

        protected void Page_Load(object sender, EventArgs e)
        {


            branchCode = Convert.ToInt32(Page.Request.Params["branchCode"].ToString());
            DateFrom = Convert.ToDateTime(Page.Request.Params["FromDate"].ToString());
            DateTo = Convert.ToDateTime(Page.Request.Params["ToDate"].ToString());


            ReportDocument CollReport = new ReportDocument();
            string reportPath = Server.MapPath("RptUploadCollection.rpt");
            CollReport.Load(reportPath);

            CollUploadReportTableAdapter ColAdp = new CollUploadReportTableAdapter();
            DataTable dt = ColAdp.GetDataByCollection(DateFrom, DateTo, branchCode);
            CollReport.SetDataSource((DataTable)dt);

            CrystalReportViewer1.ReportSource = CollReport;

            MemoryStream oStream; // using System.IO
            oStream = (MemoryStream)
            CollReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            //CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();

            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(oStream.ToArray());
            Response.End();

        }
    }
}
